package com.jikangjun.disk.file.entity;

import java.util.Date;

public class FileCopyHistory {
    
    /**
     * 历史记录ID
     */
    private String historyId;
    
    /**
     * 操作ID
     */
    private String operationId;
    
    /**
     * 源文件键
     */
    private String sourceFileKey;
    
    /**
     * 源文件名
     */
    private String sourceFileName;
    
    /**
     * 目标文件键
     */
    private String targetFileKey;
    
    /**
     * 目标文件名
     */
    private String targetFileName;
    
    /**
     * 目标路径
     */
    private String targetPath;
    
    /**
     * 文件大小
     */
    private long fileSize;
    
    /**
     * 操作状态
     */
    private String status;
    
    /**
     * 操作类型
     */
    private String operationType;
    
    /**
     * 操作用户ID
     */
    private String userId;
    
    /**
     * 操作用户名
     */
    private String userName;
    
    /**
     * 操作开始时间
     */
    private Date startTime;
    
    /**
     * 操作完成时间
     */
    private Date endTime;
    
    /**
     * 操作耗时（毫秒）
     */
    private long duration;
    
    /**
     * 错误信息
     */
    private String errorMessage;
    
    /**
     * 错误代码
     */
    private String errorCode;
    
    /**
     * 是否覆盖
     */
    private boolean overwrite;
    
    /**
     * 传输速度（字节/秒）
     */
    private long transferSpeed;
    
    /**
     * 操作描述
     */
    private String description;
    
    /**
     * 客户端IP地址
     */
    private String clientIp;
    
    /**
     * 用户代理
     */
    private String userAgent;
    
    /**
     * 会话ID
     */
    private String sessionId;

    // 默认构造函数
    public FileCopyHistory() {
        this.startTime = new Date();
    }

    // 带参数的构造函数
    public FileCopyHistory(String operationId, String sourceFileKey, String targetPath, String userId) {
        this.operationId = operationId;
        this.sourceFileKey = sourceFileKey;
        this.targetPath = targetPath;
        this.userId = userId;
        this.startTime = new Date();
    }

    // Getters and Setters
    public String getHistoryId() {
        return historyId;
    }

    public void setHistoryId(String historyId) {
        this.historyId = historyId;
    }

    public String getOperationId() {
        return operationId;
    }

    public void setOperationId(String operationId) {
        this.operationId = operationId;
    }

    public String getSourceFileKey() {
        return sourceFileKey;
    }

    public void setSourceFileKey(String sourceFileKey) {
        this.sourceFileKey = sourceFileKey;
    }

    public String getSourceFileName() {
        return sourceFileName;
    }

    public void setSourceFileName(String sourceFileName) {
        this.sourceFileName = sourceFileName;
    }

    public String getTargetFileKey() {
        return targetFileKey;
    }

    public void setTargetFileKey(String targetFileKey) {
        this.targetFileKey = targetFileKey;
    }

    public String getTargetFileName() {
        return targetFileName;
    }

    public void setTargetFileName(String targetFileName) {
        this.targetFileName = targetFileName;
    }

    public String getTargetPath() {
        return targetPath;
    }

    public void setTargetPath(String targetPath) {
        this.targetPath = targetPath;
    }

    public long getFileSize() {
        return fileSize;
    }

    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getOperationType() {
        return operationType;
    }

    public void setOperationType(String operationType) {
        this.operationType = operationType;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public boolean isOverwrite() {
        return overwrite;
    }

    public void setOverwrite(boolean overwrite) {
        this.overwrite = overwrite;
    }

    public long getTransferSpeed() {
        return transferSpeed;
    }

    public void setTransferSpeed(long transferSpeed) {
        this.transferSpeed = transferSpeed;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getClientIp() {
        return clientIp;
    }

    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    /**
     * 计算操作耗时
     */
    public void calculateDuration() {
        if (this.endTime != null && this.startTime != null) {
            this.duration = this.endTime.getTime() - this.startTime.getTime();
        }
    }

    /**
     * 完成操作
     */
    public void complete() {
        this.endTime = new Date();
        this.calculateDuration();
    }

    /**
     * 设置操作失败
     */
    public void fail(String errorMessage, String errorCode) {
        this.status = "FAILED";
        this.errorMessage = errorMessage;
        this.errorCode = errorCode;
        this.complete();
    }

    /**
     * 设置操作成功
     */
    public void success() {
        this.status = "SUCCESS";
        this.complete();
    }

    /**
     * 生成操作描述
     */
    public void generateDescription() {
        if (this.operationType != null && this.sourceFileName != null && this.targetPath != null) {
            this.description = String.format("%s文件 '%s' 到路径 '%s'", 
                this.operationType.equals("COPY") ? "复制" : "移动", 
                this.sourceFileName, 
                this.targetPath);
        }
    }

    @Override
    public String toString() {
        return "FileCopyHistory{" +
                "historyId='" + historyId + '\'' +
                ", operationId='" + operationId + '\'' +
                ", sourceFileKey='" + sourceFileKey + '\'' +
                ", sourceFileName='" + sourceFileName + '\'' +
                ", targetFileKey='" + targetFileKey + '\'' +
                ", targetFileName='" + targetFileName + '\'' +
                ", targetPath='" + targetPath + '\'' +
                ", fileSize=" + fileSize +
                ", status='" + status + '\'' +
                ", operationType='" + operationType + '\'' +
                ", userId='" + userId + '\'' +
                ", userName='" + userName + '\'' +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", duration=" + duration +
                ", errorMessage='" + errorMessage + '\'' +
                ", errorCode='" + errorCode + '\'' +
                ", overwrite=" + overwrite +
                ", transferSpeed=" + transferSpeed +
                ", description='" + description + '\'' +
                ", clientIp='" + clientIp + '\'' +
                ", userAgent='" + userAgent + '\'' +
                ", sessionId='" + sessionId + '\'' +
                '}';
    }
} 